<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>消息设置</title>
    <meta name="keywords" content="设置关键词..."/>
    <meta name="description" content="设置描述..."/>
    <meta name="author" content="DeathGhost"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <link rel="icon" href="images/icon/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <link rel="stylesheet" type="text/css" href="BootStrap/css/bootstrap.css">

    <script src="BootStrap/js/jquery.js"></script>
    <script src="BootStrap/js/bootstrap.js"></script>
</head>
<body>
<div class="page-wrap">
    <section class="page-hd">
        <header>
            <h2 class="title">消息设置</h2>
        </header>
        <hr>
    </section>
    <div class="breadcrumb">
        <ul>
            <li><a>设置</a><i class="icon-angle-right"></i></li>
            <li><a href="gudonghefenxiaoshangtable.html">消息设置</a><i class="icon-angle-right"></i></li>
            <li>详情</li>
        </ul>
    </div>

</div>

<div class="page-wrap">

    <form id="myform" class="form-inline">

        消息接受者类型:<br>
        <select class="form-control" name="usertype">
            <option value="">--所有类型--</option>
            <option value="1">用户</option>
            <option value="2">维修人员</option>
            <option value="3">医院对接人</option>
            <option value="4">股东</option>
            <option value="5">区域管理员</option>
            <option value="6">财务主管</option>
            <option value="7">会计</option>
            <option value="8">维修主管</option>
            <option value="9">老用户</option>
            <option value="10">一级分销商</option>
            <option value="11">二级分销商</option>
            <option value="12">科室对接人</option>
            <option value="14">超级管理员</option>
        </select>
        <br>
        消息类型:<br>
        <input type="text" class="form-control" placeholder="请输入消息类型" style="width:280px" name="messagetype">

        <button type="button" class="btn btn-primary" name="sousuo">搜索</button>

        <br>
        <button type="button" class="btn btn-primary" name="zenjia" onclick="add()">配置消息</button>
    </form>
</div>

<div class="breadcrumb">
    <table class="table table-striped table-bordered table-hover" style="width: 100%;margin: 20px auto">
        <thead>
        <tr class='cen'>
            <th><input type="checkbox"/></th>
            <th>消息编号</th>
            <th>消息接收者类型</th>
            <th>消息类型</th>
            <th>发送方式</th>
            <th>发送时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="tbody">

        </tbody>
    </table>
    <ul class="pagination pull-right" id="page">

    </ul>
</div>
<!--增加模态框开始-->
<div class="modal fade" id="MessageAdd_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">消息配置</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" style="width: 400px;margin: 0px auto" id="message_add_Form"
                      enctype="multipart/form-data">
                    <div class="form-group">
                        <label class="col-lg-4 control-label">发送对象：</label>
                        <div class="col-lg-8 ">
                            <select class="form-control" name="userType">
                                <option value="">--所有类型--</option>
                                <option value="1">用户</option>
                                <option value="2">维修人员</option>
                                <option value="3">医院对接人</option>
                                <option value="4">股东</option>
                                <option value="5">区域管理员</option>
                                <option value="6">财务主管</option>
                                <option value="7">会计</option>
                                <option value="8">维修主管</option>
                                <option value="9">老用户</option>
                                <option value="10">一级分销商</option>
                                <option value="11">二级分销商</option>
                                <option value="12">科室对接人</option>
                                <option value="14">超级管理员</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">消息类型：</label>
                        <div class="col-lg-8 ">
                            <input type="text" class="form-control" required="required" id="messagetype">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">发送方式：</label>
                        <div class="col-lg-8 ">
                            <select class="form-control" required="required" name="messagesendtype">
                                <option>--发送方式--</option>
                                <option value="1">短信消息</option>
                                <option value="2">微信消息</option>
                                <option value="3">邮件消息</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">消息标题：</label>
                        <div class="col-lg-8 ">
                            <input type="text" class="form-control" required="required" name="messagetitle">

                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">消息内容：</label>
                        <div class="col-lg-8 ">
                            <input type="text" class="form-control" required="required" name="messagecontent">

                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="Message_Add_save_btn" onclick=BaoCunMessage()>保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!--增加模态框结结束-->

<!--删除模态框开始-->
<div class="modal fade" id="delMessage_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <h1 style="text-align: center">你确认要删除吗？</h1>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="delMessage">删除</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!--删除模态框结束-->
<script>
    getAll(1);

    function getAll(pageNumber) {
        var usertype = $("[name=usertype]").val();
        var messagetype = $("[name=messagetype]").val();
        $.ajax({
            url: '/message/list',
            type: 'post',
            data: {"usertype": usertype, "messagetype": messagetype, "pageNumber": pageNumber, "pageSize": null},
            success: function (data) {
                if (data.result == true) {
                    var str = "";
                    for (var i = 0; i < data.xiaoxi.length; i++) {
                        str += "<tr class='cen'>";
                        str += "<td><input type='checkbox'/></td>";
                        str += "<td >" + data.xiaoxi[i].messageid + "</td>";
                        str += "<td>" + (data.xiaoxi[i].sesUser.usertype == 1 ? '新用户' : (data.xiaoxi[i].usertype == 2 ? '维修人员' : (data.xiaoxi[i].usertype == 3 ? '医院对接人' : (data.xiaoxi[i].usertype == 4 ? '股东' : (data.xiaoxi[i].usertype == 5 ? '区域管理员' : (data.xiaoxi[i].usertype == 6 ? '财务主管' : (data.xiaoxi[i].usertype == 7 ? '会计' : (data.xiaoxi[i].usertype == 8 ? '维修主管' : (data.xiaoxi[i].usertype == 9 ? '老用户' : (data.xiaoxi[i].usertype == 10 ? '一级分销商' : (data.xiaoxi[i].usertype == 11 ? '二级分销商' : (data.xiaoxi[i].usertype == 12 ? '科室对接人' : '超级管理员')))))))))))) + "</td>";
                        str += "<td>" + data.xiaoxi[i].messagetype + "</td>";
                        str += "<td>" + (data.xiaoxi[i].messagesendtype == 1 ? '短信消息' : (data.xiaoxi[i].messagesendtype == 2 ? '微信消息' : '邮件消息')) + "</td>";
                        str += "<td>" + data.xiaoxi[i].messagetime + "</td>";
                        str += "<td>";
                        str += "<input type='hidden' name='messageId' value='" + data.xiaoxi[i].messageid + "'>";
                        str += "<a title='编辑' class='mr-5' onclick=Update()>编辑</a>";
                        str += " <a  name='del'> 删除</a>";
                        str += "</td></tr>";

                    }
                    $("#tbody").html(str);

                    var page = "";
                    page += '<li class="' + (data.page.pageNum == 1 ? 'disabled' : '') + '"><a onclick="getAll(' + data.page.prePage + ')" >上一页</a></li>';
                    for (var i = 1; i <= data.page.pages; i++) {
                        page += ' <li class="' + (data.page.pageNum == i ? 'active' : '') + '"><a onclick="getAll(' + i + ')">' + i + '<span class="sr-only"></span></a></li>';
                    }
                    page += ' <li ><a onclick="getAll(' + data.page.nextPage + ')" >下一页</a></li>';
                    $("#page").html(page);
                }
                del();
                delMessage();
            }
        });

    }


    //删除弹出模态框

    function del() {
        $("[name=del]").click(function () {
            $("#delMessage_modal").modal("show");
        })

    }

    //确认删除删除模态框
    delMessage();

    function delMessage() {
        var messageId = $("[name=messageId]").val();

        $("#delMessage").click(function () {
            $.ajax({
                type: 'post',
                url: '/message/delete',
                data: {"messageid": messageId},
                success: function (data) {
                    $("#delMessage_modal").modal("hide");
                    getAll(1);
                }
            });
        })
    }

    //增加模态框弹出
    function add() {
        $("#MessageAdd_modal").modal("show");
    }

    //增加
    function BaoCunMessage() {
        $.ajax({
            url: '/message/add',
            type: 'post',
            data: {
                "userType": $("[name=userType]").val(),
                "messagetype": $("#messagetype").val(),
                "messagesendtype": $("[name=messagesendtype]").val(),
                "messagetitle": $("[name=messagetitle]").val(),
                "messagecontent": $("[name=messagecontent]").val()
            },
            success: function (data) {
                $("#MessageAdd_modal").modal("hide");
                getAll(1);
            }
        });
    }


</script>
</body>
</html>